<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>修改博客</title>
<meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="format-detection" content="telephone=no" />
<link type="text/css" rel="stylesheet" href="assets/css/bootstrap.min.css">
<link type="text/css" rel="stylesheet" href="assets/css/style.css">
</head>

<body class="Spage_body">
<!-- top-head -->
<div class="top_head">
	修改博客
	<a href="center" class="top_head_back"><img src="assets/images/back_btn.png"></a>
</div>
<!-- top-head -->
<!-- wrap -->
<!-- login_box -->
<div class="container login_box">
	<form>
		<div class="login_input" style="float:left;">
        	<div class="login_input_d1">
            	<p class="col-xs-3 col-sm-2 login_input_d1_p1">标题</p>
                <p class="col-xs-9 col-sm-10 login_input_d1_p2">
                	<input type="text" name="title" id="title" placeholder="请输入标题">
                </p>
            </div>
            <div class="login_input_d1">
            	<p class="col-xs-3 col-sm-2 login_input_d1_p1">标签</p>
                <p class="col-xs-9 col-sm-10 login_input_d1_p2">
                	<input type="text" name="tag" id="tag" placeholder="请输入标签">
                </p>
            </div>
            <div class="login_input_d1" style="height:auto;float:left;">
                <p class="col-xs-3 col-sm-2 login_input_d2_p1">内容</p>
                <p class="col-xs-9 col-sm-10 login_input_d2_p2" style="height:auto;">
                    <script id="editor" type="text/plain" style="width:100%;height:500px;">初始化的内容。</script>
                </p>
            </div>
        </div>
        <div class="login_btn col-xs-12">
        	<input id="saveBlog" type="button" value="保存">
        </div>
    </form>
</div>
<!-- login_box -->
<!-- wrap -->
<script type="text/javascript" src="assets/scripts/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="assets/scripts/hr-jquery.js"></script>
<!-- 配置文件 -->
<script type="text/javascript" charset="UTF-8" src="./ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" charset="utf-8" src="./ueditor/ueditor.all.min.js"> </script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
<script type="text/javascript" charset="utf-8" src="./ueditor/lang/zh-cn/zh-cn.js"></script>
<script>
	$(document).ready(function(){
		//实例化编辑器
	    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
	    var ue = UE.getEditor('editor',{
	    	//这里可以选择自己需要的工具按钮名称,此处仅选择如下五个
            toolbars:[[
                       'fullscreen', 'source', '|', 'undo', 'redo', '|',
                       'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
                       'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
                       'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
                       'directionalityltr', 'directionalityrtl', 'indent', '|',
                       'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
                       'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
                       'simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'gmap', 'insertframe', 'insertcode', 'webapp', 'pagebreak', 'template', 'background', '|',
                       'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|',
                       'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
                       'print', 'preview', 'searchreplace', 'drafts', 'help'
                   ]],
            //focus时自动清空初始化时的内容
            autoClearinitialContent:true,
            //关闭字数统计
            wordCount:false,
            //关闭elementPath
            elementPathEnabled:false,
            //默认的编辑区域高度
            initialFrameHeight:300
            //更多其他参数，请参考ueditor.config.js中的配置项
	    });
		
		ue.ready(function(){
			$.get("getBlog.do",function(data){
				var $title = $("#title").val(data.title);
				var $tag = $("#tag").val(data.tag);
				ue.setContent(data.content);
			});
			
			$("#saveBlog").click(function(){
				saveBlog();
			});
		});
		
		
		function saveBlog(){
			var $title = $("#title").val();
			var $tag = $("#tag").val();
			var $content = ue.getContent();
			var $dataObjdct = {
					"title":$title,
					"tag":$tag,
					"content":$content
			}
			
			$.ajax({
				type:"post",
				url:"saveblog",
				dataType:"json",
				contentType:"application/json;charset=utf-8",
				data:JSON.stringify($dataObjdct),
				//data:$dataObjdct,
				success:function(data){
					if(data.res == "1"){
						alert("修改成功！");
						window.location.href="center";
					}
				}
			})
		}
	});
</script>
</body>
</html>